//Nathan Young
//Hangman Game
import java.util.Scanner;
import java.util.Random;
public class hangman2
{
	static Scanner console = new Scanner(System.in);
	public static void main(String[]args)
	{
		System.out.println("Hangman Started");
		System.out.println("Elements are the topic");
		Random generator = new Random();
		int elem = generator.nextInt(4);
		String[] elements;
		elements = new String[4];
		elements[0] = "Gold";
		elements[1] = "Silver";
		elements[2] = "Mercury";
		elements[3] = "Carbon";
		
		char[] previousguesses;
		previousguesses = new char[20];
		
		char[] puzzleanswer;
		puzzleanswer = new char[30];
		int correctanswer = 0;
		int lengthofword;
		int badguess = 0;
		String caseword, word;
		String stringguess;
		char guess;
		caseword = elements[elem];
		word = caseword.toUpperCase();
		lengthofword = word.length();
		int correct = 0;
		int response = 0;
		int c = 0;
		for(int z = 0; z < lengthofword; z++)
			puzzleanswer[z] = '_';
		do
		{
			for(int y = 0; y < lengthofword; y++)
				System.out.print(puzzleanswer[y] + " ");
			System.out.println();
			System.out.println("Guess:");
			stringguess = console.next();
			stringguess = stringguess.toUpperCase();
			guess = stringguess.charAt(0);
			response = 0;
			for(int x = 0; x < lengthofword; x++)
			{
				if(guess == word.charAt(x) && puzzleanswer[x] == '_')
				{
					response = 1;
					correctanswer++;
					puzzleanswer[x] = guess;
				}
				else if(guess == word.charAt(x) && puzzleanswer[x] != '_')
				{
					response = 2;
				}
				else
				{
					
				}

			}
				if(response == 1)
				{
					System.out.println("Correct!");
				}
				else if(response == 2)
				{
					System.out.println("The letter " + guess + " has already been used.");
				}
				else
				{
					System.out.println("There is no " + guess + " in this word.");
					badguess++;
				}
			for(int m = 0; m <= c; m++)
			{
				if(guess == previousguesses[m] && response != 2)
					System.out.println("The letter " + guess + " has already been used.");
				else
				{
				
				}
			}
			System.out.println("Previous guesses are: ");
			previousguesses[c] = guess;
			c++;
			for(int b = 0; b < c; b++)
				System.out.println(previousguesses[b] + " ");
		}while(badguess < 10 && correctanswer < lengthofword);
		if(correctanswer == lengthofword)
		{
			System.out.println("You win");
			System.out.println("The word was " + word);
		}
		else
		{
			System.out.println("You lose");
			System.out.println("The word was " + word);
		}
	}
}

/*

*/